package com.clkj.xiuzheng.dao.shangcheng;

import com.clkj.xiuzheng.pojo.shangcheng.ProductDiscussion;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper;

import java.util.List;

@Repository
public interface ScDiscussionMapper extends Mapper<ProductDiscussion>, MySqlMapper<ProductDiscussion>{
    @Select({  "<script>",
               "SELECT d.*,p.product_name,u.user_name ",
               "FROM t_xz_productDiscussion d ",
               "LEFT JOIN t_xz_product p ON d.product_id =p.product_id ",
               "LEFT JOIN t_xz_user u on d.user_id = u.user_id WHERE 1=1",
               "<if test ='companyId!=null'>",
               "and d.company_id = #{companyId} ",
               "</if>",
               "<if test ='parentId!=null'>",
               "and d.discussion_parent_id = #{parentId} ",
               "</if>",
               "<if test ='productId!=null'>",
               "and p.product_id = #{productId} ",
               "</if>",
               "<if test ='discussionType!=null'>",
               "and d.discussion_type = #{discussionType} ",
               "</if>",
               "</script>"
             })
    List<ProductDiscussion> getDiscussionByCompanyId(@Param("companyId") Integer companyId, @Param("parentId") Integer parentId, @Param("productId") Integer productId, @Param("discussionType") Integer discussionType);

    @Select("select * from t_xz_productDiscussion a left join t_xz_user b on a.user_id = b.user_id where a.product_id = #{productId}")
    List<ProductDiscussion> listDiscussion(@Param("productId")Integer productId);

    @Select("select  top 1 * from t_xz_productDiscussion  where product_id = #{productId} and discussion_parent_id = 0 order by discussion_id desc")
    List<ProductDiscussion> listTopDiscussionByProductId(@Param("productId")Integer productId);
}
